<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\admin\model;

use think\Model;

class Cate extends Model{
   
    /*
     *排序好的栏目 
     */
    
    public function sort($pid=0,$level=0){
        static $arr= array();
        $data= $this->order('sort desc')->select();
        foreach( $data as $k => $v){
            if($v['pid']==$pid){
               $v['level']=$level;
               $arr[]=$v;
               $this->sort($v['id'],$level+1);
            }
        }
          return $arr;
    }
    
    
    public function getChildrenId($cateid){
        static $arr= array();
        
        $cateres= $this->select();
       
        foreach ( $cateres as $k => $v){
            if($v['pid']==$cateid){
                $arr[]=$v['id'];
                $this->getChildrenId($v['id']);
            }
        }
        return $arr;
    }
}